//
//  HSCButton.m
//  AAAA
//
//  Created by zhangmh on 12-7-20.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "HSCButton.h"
#import "User.h"
#import "MovieLabelModel.h"

@interface HSCButton ()
{
    UIImageView *pImgLike;
    UIImageView *pImgDelete;
    
    //图片
    UIImageView *ImgPic;
    //图片数量
    UILabel *lblNum;
    //时间
    UILabel *lblTime;
    //距离
    UILabel *lblPlace;
    
    //影签
    UIView *pViewLabs;
    
    UILabel *lblName;
    UIImageView *imgSex;
    UILabel *lblAge;
    UILabel *lblAddress;
}

@end

@implementation HSCButton

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        ImgPic = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height - 50)];
        [ImgPic setImage:[UIImage imageNamed:@"publish_1"]];
        [ImgPic setContentMode:UIViewContentModeScaleAspectFill];
        [ImgPic setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
        [self addSubview:ImgPic];
        
        UIImageView *imgNum = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 30, 20)];
        [imgNum setImage:[UIImage imageNamed:@"date_imgNum"]];
        [self addSubview:imgNum];
        
        

        
//        UIImageView *imgLeft = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 10, 30)];
//        [imgLeft setImage:[UIImage imageNamed:@"bg_labels_left"]];
//        [imgLeft setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin];
//        [pViewLabs addSubview:imgLeft];
//        
//        UIImageView *imgRight = [[UIImageView alloc] initWithFrame:CGRectMake(imgLeft.frame.size.width, 0, pViewLabs.frame.size.width - 35, 30)];
//        [imgRight setImage:[UIImage imageNamed:@"bg_labels_right"]];
//        [imgRight setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
//        [pViewLabs addSubview:imgRight];
        
        //图片数量
        lblNum = [[UILabel alloc] initWithFrame:CGRectMake(25, 6, 10, 10)];
        [lblNum setText:@"1"];
        [lblNum setFont:[UIFont systemFontOfSize:8]];
        [lblNum setTextColor:[UIColor whiteColor]];
        [self addSubview:lblNum];
        
        UIView *viewBottom = [[UIView alloc] initWithFrame:CGRectMake(0, self.frame.size.height - 80, self.frame.size.width, 80)];
        [viewBottom setAutoresizingMask:UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
        [viewBottom setBackgroundColor:[UIColor clearColor]];
        [self addSubview:viewBottom];
        
        UIView *viewBg = [[UIView alloc] initWithFrame:CGRectMake(0, 20, viewBottom.frame.size.width + 100, 100)];
        [viewBg setBackgroundColor:[UIColor whiteColor]];
        [viewBottom addSubview:viewBg];
        
        pViewLabs = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 30)];
        [pViewLabs setHidden:YES];
        [viewBottom addSubview:pViewLabs];
        
        UIImageView *imgBG = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, pViewLabs.frame.size.width, pViewLabs.frame.size.height)];
        [pViewLabs setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin];
        [imgBG setImage:[UIImage imageNamed:@"bg_labels"]];
        [pViewLabs addSubview:imgBG];
        
        
        
        
        
        //名字
        lblName = [[UILabel alloc] initWithFrame:CGRectMake(15, 45, 0, 15)];
        [lblName setText:@"--"];
        [lblName setFont:[UIFont systemFontOfSize:14]];
        [viewBottom addSubview:lblName];

        imgSex = [[UIImageView alloc] initWithFrame:CGRectMake(lblName.frame.origin.x + lblName.frame.size.width, 45, 12, 16)];
        [imgSex setImage:[UIImage imageNamed:@"sex_boy"]];
        [viewBottom addSubview:imgSex];
        
        //年龄
        lblAge = [[UILabel alloc] initWithFrame:CGRectMake(imgSex.frame.origin.x + imgSex.frame.size.width, 45, 0, 15)];
        [lblAge setText:@"--"];
        [lblAge setFont:[UIFont systemFontOfSize:14]];
        [viewBottom addSubview:lblAge];

//        lblAddress = [[UILabel alloc] initWithFrame:CGRectMake(15, 30, self.frame.size.width, 10)];
//        [lblAddress setText:@"--"];
//        [lblAddress setFont:[UIFont systemFontOfSize:13]];
//        [lblAddress setTextColor:[UIColor lightGrayColor]];
//        [viewBottom addSubview:lblAddress];
        
        
        
//        UIImageView *imgTime = [[UIImageView alloc] initWithFrame:CGRectMake(10, 15, 20, 20)];
//        [imgTime setImage:[UIImage imageNamed:@"icon_time"]];
//        [viewBottom addSubview:imgTime];
//        
//        //时间
//        lblTime = [[UILabel alloc] initWithFrame:CGRectMake(30, 15, self.frame.size.width / 2 - 25, 20)];
//        [lblTime setText:@"--"];
//        [lblTime setTextColor:[UIColor lightGrayColor]];
//        [lblTime setFont:[UIFont systemFontOfSize:12]];
//        [viewBottom addSubview:lblTime];
//        
//        UIImageView *imgPlace = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width / 2, 15, 20, 20)];
//        [imgPlace setImage:[UIImage imageNamed:@"icon_place"]];
//        [viewBottom addSubview:imgPlace];
//        
//        //距离
        lblPlace = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width / 2 + 25, 45, self.frame.size.width / 2 - 15, 20)];
        [lblPlace setTextColor:[UIColor lightGrayColor]];
        [lblPlace setFont:[UIFont systemFontOfSize:12]];
        [lblPlace setText:@"--"];
        [viewBottom addSubview:lblPlace];
        
        UIImageView *imgLike = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 50, 50)];
        [imgLike setImage:[UIImage imageNamed:@"love"]];
        [self addSubview:imgLike];
        [imgLike setHidden:YES];
        pImgLike = imgLike;
        
        UIImageView *imgDelete = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width - 10 - 50, 10, 50, 50)];
        [imgDelete setImage:[UIImage imageNamed:@"notLike"]];
        [self addSubview:imgDelete];
        [imgDelete setHidden:YES];
        pImgDelete = imgDelete;
    }
    return self;
}

- (void)setPEm_Movie_Way:(EM_Move_Way)pEm_Movie_Way
{
    _pEm_Movie_Way = pEm_Movie_Way;
    switch (pEm_Movie_Way) {
        case em_no:
        {
            [pImgDelete setHidden:YES];
            [pImgLike setHidden:YES];
        }
            break;
            
        case em_left:
        {
            [pImgDelete setHidden:NO];
            [pImgLike setHidden:YES];
        }
            break;
            
        case em_right:
        {
            [pImgDelete setHidden:YES];
            [pImgLike setHidden:NO];
        }
            break;
    }
}

- (void)setPUser:(XYuser *)pUser {
    _pUser = pUser;
    [ImgPic sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/api/common/file/imgGet?fid=%@", IP, _pUser.headImage]]];
    [lblNum setText:_pUser.albumNum];
    [lblTime setText:_pUser.activeTimeLast];
    [lblPlace setText:_pUser.distance];
    
    [lblName setText:_pUser.nickname];
    [lblName sizeToFit];
    [imgSex setImage:[UIImage imageNamed:[_pUser.userSex isEqualToString:@"1"]?@"sex_boy":@"sex_girl"]];
    [imgSex setFrame:CGRectMake(lblName.frame.origin.x + lblName.frame.size.width, imgSex.frame.origin.y, imgSex.frame.size.width, imgSex.frame.size.height)];
    [lblAge setText:_pUser.userAge];
    [lblAge sizeToFit];
    [lblAge setFrame:CGRectMake(imgSex.frame.origin.x + imgSex.frame.size.width, lblAge.frame.origin.y, lblAge.frame.size.width, lblAge.frame.size.height)];
    if ([_pUser.userSex isEqualToString:@"1"]) {
        [lblAge setTextColor:[UIColor colorWithRed:108/255.0f green:181/255.0f blue:255/255.0f alpha:1]];
    } else {
        [lblAge setTextColor:[UIColor colorWithRed:252/255.0f green:110/255.0f blue:108/255.0f alpha:1]];
    }
    [lblPlace setText:[NSString stringWithFormat:@"%@(%@)", _pUser.distance, _pUser.address]];

    
    
    
    
    BOOL labelsHidden = YES;
    NSString *strMessage = @"共同爱好:";
    for (int i = 0; i < _pUser.labels.count; i++) {
        MovieLabelModel *modelTheLabel = [_pUser.labels objectAtIndex:i];
        User *user = [User defaultUser];
        for (MovieLabelModel *model in user.labels) {
            if ([model.uuid isEqualToString:modelTheLabel.uuid]) {
                labelsHidden = NO;
                strMessage = [NSString stringWithFormat:@"%@ %@", strMessage, model.name];
            }
        }
    }
    UILabel *lblLabels = [[UILabel alloc] initWithFrame: CGRectMake(15, 0, [UIScreen mainScreen].bounds.size.width - 60, pViewLabs.frame.size.height)];
    [lblLabels setFont:[UIFont systemFontOfSize:14]];
    [lblLabels setText:strMessage];
    [pViewLabs addSubview:lblLabels];
    [pViewLabs setHidden:labelsHidden];
}

@end
